/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.header.InReplyToHeader;
import java.text.ParseException;

/**
 * The In-Reply-To header field enumerates the Call-IDs that this call
 * references or returns. These Call-IDs may have been cached by the client
 * then included in this header field in a return call.
 * <p>
 * This allows automatic call distribution systems to route return calls to the
 * originator of the first call. This also allows callees to filter calls, so
 * that only return calls for calls they originated will be accepted. This
 * field is not a substitute for request authentication.
 * <p>
 * For Example:<br>
 * <code>In-Reply-To: 70710@saturn.jcp.org, 17320@saturn.jcp.org</code>
 *
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class InReplyToHeaderImpl extends HeaderBase implements InReplyToHeader {
    private String callId;

    private final static InReplyToHeaderParser parser = new InReplyToHeaderParser();

    public InReplyToHeaderImpl() {
        super(InReplyToHeader.NAME);
    }

    InReplyToHeaderImpl(byte[] data, int start, int end) {
        super(InReplyToHeader.NAME, data, start, end);
    }

    public Object clone() {
        final InReplyToHeaderImpl header = new InReplyToHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.callId = this.callId;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return callId;
    }

    /**
     * Sets the Call-Id of the InReplyToHeader. The CallId parameter uniquely
     * identifies a serious of messages within a dialogue.
     *
     * @param callId the string value of the Call-Id of this InReplyToHeader.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the callId value.
     */
    public void setCallId(String callId) throws ParseException {
        parse();
        this.callId = callId;
        invalidateHeaderData();
    }

    /**
     * Returns the Call-Id of InReplyToHeader. The CallId parameter uniquely
     * identifies a series of messages within a dialogue.
     *
     * @return the String value of the Call-Id of this InReplyToHeader
     */
    public String getCallId() {
        parse();
        return callId;
    }
}
/*
 * $Log$
 */